﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;

namespace JasLib.Collections
{
    /// <summary>
    /// This helps implement a collection without cluttering the implementation with
    /// unused, redundant, or unnecessary interface functions.
    /// </summary>
    [Serializable]
    public abstract class SimplifiedCollectionBase<T> :
        ICollection<T>, ICollection,
        INotifyCollectionChanged, INotifyPropertyChanging, INotifyPropertyChanged
    {
        protected static PropertyChangingEventArgs s_countChangingEventArgs = EventArgsCache.GetNotifyPropertyChangingEventArgs("Count");
        protected static PropertyChangedEventArgs s_countChangedEventArgs = EventArgsCache.GetNotifyPropertyChangedEventArgs("Count");

        public virtual void Add(T item)
        {
            return;
        }

        public virtual void Clear()
        {
            return;
        }

        public virtual bool Contains(T item)
        {
            return false;
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            foreach (T t in this)
                array[arrayIndex++] = t;
        }

        public virtual int Count
        {
            get { return 0; }
        }

        public bool IsEmpty
        {
            get { return (Count == 0); }
        }

        public virtual bool IsReadOnly
        {
            get { return false; }
        }

        public virtual bool Remove(T item)
        {
            return false;
        }

        public virtual IEnumerator<T> GetEnumerator()
        {
            return Enumerable.Empty<T>().GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return (this as IEnumerable<T>).GetEnumerator();
        }

        public void CopyTo(Array array, int index)
        {
            foreach (T t in this)
                array.SetValue(t, index++);
        }

        public virtual bool IsSynchronized
        {
            get { return false; }
        }

        public virtual object SyncRoot
        {
            get { return this; }
        }

        #region INotifyCollectionChanged

        public event NotifyCollectionChangedEventHandler CollectionChanged;

        public void OnAdd()
        {
        }

        public void OnRemove()
        {
        }

        public void OnReplace()
        {
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        #endregion
    }
}
